﻿using System.Collections;
using System.Data;

namespace Triad.DAL.NorthWind
{
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Linq;

    /// <summary>
    /// General DB Stored Procs
    /// </summary>
    public class NorthWindDBSProcs : DBBase
    {
        /// <summary>
        /// Dynamically creates OrderDB class (LINQ, Lambda or Sprocs) by reading from web.config file 'appSettings'
        /// </summary>
        /// <returns>new Instance of the Class</returns>
        public static NorthWindDBSProcs Create()
        {
            string typeString = ConfigurationManager.AppSettings["DALType"];
            Type dbType = Type.GetType("Triad.DAL.NorthWind.NorthWind" + typeString);
            return (NorthWindDBSProcs)Activator.CreateInstance(dbType);
        }
        #region Select Statements


        public virtual IEnumerable<CustOrdersOrdersResult> GetCustomerOrders(string p_CustomerId)
        {
            using (NorthWindDataContext context = DataContext)
            {

                return context.CustOrdersOrders(p_CustomerId).ToArray();
            }
        }

        public virtual IEnumerable<CustOrdersDetailResult> GetCustomerOrdersDetail(int? p_OrdersDetailId)
        {
            using (NorthWindDataContext context = DataContext)
            {

                return context.CustOrdersDetail(p_OrdersDetailId).ToArray();
            }
        }
        #endregion


        #region DataReader
        public DataTable GetCustOrders(int p_OrderId)
        {
            Triad.DAL.TriadDataReader objReader = new Triad.DAL.TriadDataReader();
            Dictionary<string,string> htSqlParameters = new Dictionary<string, string>();

            htSqlParameters.Add("@OrderId", p_OrderId.ToString());
            string ErrorMsg="";
            DataTable dt = GetReadOnlyData("CustOrdersDetail", htSqlParameters,ref ErrorMsg);
            return dt;

        }

        #endregion 


    }
}
